﻿#include <iostream>
using namespace std;
int max2(int a, int b) {
	if (a > b)return a;
	else return b;
}
int max3(int a, int b, int c) {
	if (a > b && a > c)return a;
	else if (b > a && b > c)return b;
	else return c;
}
int max4(int a, int b, int c, int d) {
	if (a > b && a > c && a > d)return a;
	else if (a<b && b>c && b > d)return b;
	else if (a<c && c>b && c > d)return c;
	else return d;
}
int commonDivisor(int x1, int x2) {
	int t = 1;//放公约数
	for (int i = 1; i <= max2(x1, x2); i++) {
		if (x1 % i == 0 && x2 % i == 0) {
			t = i;
		}
	}
	return t;
}
int commonDivisor(int x1, int x2, int x3) {
	int t = 1;//放公约数
	for (int i = 1; i <= max3(x1, x2, x3); i++) {
		if (x1 % i == 0 && x2 % i == 0 && x3 % i == 0) {
			t = i;
		}
	}
	return t;
}
int commonDivisor(int x1, int x2, int x3, int x4) {
	int t = 1;//放公约数
	for (int i = 1; i <= max4(x1, x2, x3, x4); i++) {
		if (x1 % i == 0 && x2 % i == 0 && x3 % i == 0) {
			t = i;
		}
	}
	return t;
}
int main()
{
	cout << "请选择要计算几个整数的最大公约数(2||3||4):";
	int n;
	int a2, b2;
	int a3, b3, c3;
	int a4, b4, c4, d4;
	cin >> n;
	if (n == 2) {
		cout << "请输入2个整数:";

		cin >> a2 >> b2;
		cout << "------------------------------" << endl;
		int res2 = commonDivisor(a2, b2);
		cout << "整数" << a2 << "," << b2 << "的最大公约数为:" << res2;
	}
	else if (n == 3) {
		cout << "请输入3个整数:";

		cin >> a3 >> b3 >> c3;
		cout << "------------------------------" << endl;
		int res3 = commonDivisor(a3, b3, c3);
		cout << "整数" << a3 << "," << b3 << "," << c3 << "的最大公约数为:" << res3;
	}
	else if (n == 4) {
		cout << "请输入4个整数:";

		cin >> a4 >> b4 >> c4 >> d4;
		cout << "------------------------------" << endl;
		int res4 = commonDivisor(a4, b4, c4, d4);
		cout << "整数" << a4 << "," << b4 << "," << c4 << "," << d4 << "的最大公约数为:" << res4;
	}
	else
		cout << "请输入2或3或4";
	return 0;
}